<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            margin: 20px auto;
            border: 1px solid #000;
            line-height: 100px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div>
        123
    </div>
    <div>
        456
    </div>
    <div>
        789
    </div>
</body>
</html>
<script>
    var divs = document.querySelectorAll('div')
    for(var i = 0 ; i< divs.length;i++){
       divs[i].onclick = function () {
            alert(this.innerHTML)
       }
    }
</script>